home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-06-29 | 10.8 KB | 264 lines | [TEXT/MPS ] |
- { FracAppPalette:
- Copyright 1988 by Bob. All rights reserved, since Bob has all rights.
- February 1, 1988.
- Written by Bo3b Johnson of Developer Technical Support. }
-
- UNIT UFracApp;
-
- (*
-
- This is a not too small application which can calculate a fractal in full color
- on the Mac II, using direct 881 code for speed. It saves files on disk as PICT.
- For full info, see the implementation. This version specifically is set up to
- be fully compatible, and does not support color table animation.
-
- *)
-
- INTERFACE
-
- USES
- {$LOAD FracApp881.LOAD}
- MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
- UMacAppUtilities, UViewCoords, UFailure,
- UMemory, UMenuSetup, UObject, UList, UAssociation, UMacApp,
- PaletteMgr, UPrinting, OffScreen; { adds new offworld calls }
- {$LOAD}
-
- CONST
-
- {Command numbers}
-
- kSignature = 'Arf '; {Application signature}
- kFileType = 'PICT'; {File-type code used for document files
- created by this application}
- kFracAppWindowID = 1001; {This is passed to NewSimpleWindow as the
- resource ID of the the WIND Resource
- which defines the window for this
- application's documents}
- kMultiDialog = 1000; { Dialog Id for multipage dialog, gets number of pages to do.}
- kHorItem = 3; { item in dialog for EditText of horizontal page count. }
- kVerItem = 4; { item in dialog for EditText of vertical page count. }
-
- kStaggerAmount = 30;
- kPICTHeaderSize = 512; { 512 bytes off the file are used for our info and print info. }
- kSelPattern = 128; { pattern resource Id. }
- kNewFractal = 1000; { item Id for New Fractal menu option. }
- kNewMultiPage = 1001; { item Id for New Multipage… menu option. }
- kPageId = 1001; { 'page' resource Id. }
- kClut = 501; { Res Id for the clut resource that we use for offscreen. }
- kNumColors = 195; { number of colors we animate, and use in calculation. }
- kWrongMachine = 1000; { error code if we cannot run, from ForceEnvirons. }
-
- kRectRight = 608; { Full page size rectangle for color Tek Printer }
- kRectBottom = 798; { Full page size for bottom }
-
- envDontCare = 0; { don't care is always 0, for ForceEnvirons. }
-
- TYPE
- { The header record for each of the files saved by FracApp. This header includes the
- pertinent data that allows a fractal to be restarted, as well as displayed
- on the screen. The print record follows this info in the first 512 bytes of a file,
- but that info is read by the standard DoRead/DoWrite methods. Some of the fields
- are LongInts to avoid rounding errors during calculations. }
- FracRecord = RECORD
- fType: OSType; { 4 set as 'Arf ' for these documents. }
- hdrId: Integer; { 2 as 'FA' FracApp header ID. }
- version: Integer; { 2 file version decides type of file. }
- done: Boolean; { 2 if the fractal is finished or not. }
- realMin: Extended; { 12 minimum value of fractal on real/p axis. }
- realMax: Extended; { 12 maximum value of fractal on real/p axis. }
- imagMin: Extended; { 12 minimum on imaginary/q axis. }
- imagMax: Extended; { 12 maximum on imaginary/q axis. }
- deltaP: Extended; { 12 horizontal step size in fractal space. }
- deltaQ: Extended; { 12 vertical step size in fractal space. }
- plotWidth: LongInt; { 4 width of fractal area in pixels. }
- plotHeight: LongInt; { 4 height of fractal area in pixels. }
- calcRect: Rect; { 8 rectangle surrounding the window it was built for. }
- curRow: LongInt; { 4 counter for current pixel position to be done. Vertical. }
- curCol: LongInt; { 4 counter for current pixel. Horizontal. }
- elapsedTime: LongInt; { 4 amount of time to do this fractal in seconds. }
- END; { FracRecord. }
-
-
-
- {------------------------------- Application -------------------------------}
-
- TFracAppApplication = OBJECT(TApplication)
-
-
- PROCEDURE TFracAppApplication.IFracAppApplication (itsMainFileType: OSType);
- {Initializes the application and globals.}
-
- (* PROCEDURE TFracAppApplication.Close; OVERRIDE;
- { Removes idle coHandler as we exit. }
- *)
- FUNCTION TFracAppApplication.DoMakeDocument(
- itsCmdNumber: CmdNumber): TDocument; OVERRIDE;
- {Launches a TFracAppDocument; called when application's icon is
- opened, and when New or Open is requested by the user.
- Every application which uses Documents MUST override this
- method}
-
- { PROCEDURE TFracAppApplication.DoIdle (Phase: IdlePhase); OVERRIDE;
- { Performs Idle time processing for the application. This will do the
- fractal calculation during the idle times. It will allow each open
- view a chance to calculate. }
-
- END; { TFracAppApplication }
-
-
- {------------------------------- Document -------------------------------}
-
- TFracAppDocument = OBJECT(TDocument)
-
- { Now the fields that are special to the fractal itself. These are the
- variables that make up the display state and the definition of the
- fractal itself. They are associated with the document so they can
- be stored in a file, and read back in. Essentially a global state for
- each fractal document. }
-
- fFracHeader: FracRecord; { global state on fractal. }
- fStartTime: LongInt; { starting time of calculations. }
- fBigBuff: Ptr; { pointer to offscreen data }
- fDrawingDevice: GDHandle; { handle to our offscreen gDevice. }
- fDrawingPort: CGrafPtr; { pointer to drawing buffer. }
-
- fFracAppView: TFracAppView;
- {Every document object must preserve references to all the views it
- creates as fields of the document object, since DoMakeWindows
- will need to know which views to install in the windows it
- creates}
-
-
- PROCEDURE TFracAppDocument.BuildOffWorld (sizeOfDoc: Rect);
- { Allocates offscreen gDevice and port for document data. }
-
- PROCEDURE TFracAppDocument.SetUpConstants;
- { Sets up starting constants for calculation. }
-
- PROCEDURE TFracAppDocument.IFracAppDocument;
- {Init routine for the document, sets up the object, then the fractal default state. }
-
- PROCEDURE TFracAppDocument.DoInitialState; OVERRIDE;
- { Does the work for a New operation, where we start with a new fractal
- that doesn't have any stored data. This is set up the view with no
- data and set up the fractal coordinates to the default. }
-
- PROCEDURE TFracAppDocument.DoMakeWindows; OVERRIDE;
- {Launches the window which will represent the document on the
- screen. Every document which has any screen display MUST
- override this method}
-
- PROCEDURE TFracAppDocument.DoMakeViews(forPrinting: BOOLEAN); OVERRIDE;
- {Launches the view which is seen in the document's window. Every
- document which has any screen display or which can be printed
- MUST override this method}
-
- PROCEDURE TFracAppDocument.DoNeedDiskSpace(VAR dataForkBytes,
- rsrcForkBytes: LONGINT); OVERRIDE;
- { Finds out the entire size of the object to be saved into the file so that the
- correct amount of disk space can be used. }
-
- PROCEDURE TFracAppDocument.DoRead(aRefNum: INTEGER; rsrcExists,
- forPrinting: BOOLEAN); OVERRIDE;
- { Reads in the data out of the data fork of the file, and stows it into the
- document’s bitMap. Also resets the vars in the document object to match
- the saved values from the header. }
-
- PROCEDURE TFracAppDocument.DoWrite(aRefNum: INTEGER;
- makingCopy: BOOLEAN); OVERRIDE;
- { Converts the data in the document’s port into a PICT, then writes that block
- out to the file, making it into a standard PICT file. }
-
- PROCEDURE TFracAppDocument.FreeData; OVERRIDE;
- { Free method usually used for Rever operation, kept here to show the
- normal Free approach. }
-
- PROCEDURE TFracAppDocument.Free; OVERRIDE;
- { Free method for our document. It disposes the data block of the picture
- data that was read in from the disk, and kills offscreen stuff. }
-
- FUNCTION TFracAppDocument.DoIdle(phase: IdlePhase): BOOLEAN; OVERRIDE;
- { Idle for the doc to call CalcCity and start up new auto docs if needed. }
-
- FUNCTION TFracAppDocument.CalcCity: BOOLEAN;
- { Does the idle time calculations for the document. This is for the actual
- fractal calculations. It is called by the handler for the Application
- DoIdle. It is called for all open documents. }
-
- END; { TFracAppDocument }
-
-
-
- {------------------------------- View -------------------------------}
-
- TFracAppView = OBJECT(TView)
-
- { These fields are for the use of the view, and help define our specific view, that
- is the offscreen bitMap representation of the fractal. }
- fSelectionRect: Rect; { rectangle that is current selection }
- fFracAppDocument: TFracAppDocument; { handy to avoid type coercion. }
-
- PROCEDURE TFracAppView.IFracAppView (itsDocument: TFracAppDocument;
- sizeOfView: Rect);
- { Inits the view object itself. }
-
- PROCEDURE TFracAppView.Draw(area: Rect); OVERRIDE;
- {Draws the view seen in the window. Every nonblank view MUST
- override this method}
-
- FUNCTION TFracAppView.DoMenuCommand(
- aCmdNumber: CmdNumber): TCommand; OVERRIDE;
- { Handle the menu choices for New Fractal out of the Fractal Menu. }
-
- PROCEDURE TFracAppView.DoSetupMenus; OVERRIDE;
- { Set up the New Fractal menus choice in Fractal Menu, based on selection. }
-
- FUNCTION TFracAppView.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand; OVERRIDE;
- { Handle the mouse events in the view. Needs to do the selection of a new
- range for the next fractal to be calculated. }
-
- PROCEDURE TFracAppView.DoHighlightSelection(fromHL, toHL: HLState); OVERRIDE;
- { Highlight the current selection rectangle if there is one. }
-
- END; { TFracAppView }
-
-
- {------------------------------- Command -------------------------------}
-
- TAreaSelector = OBJECT(TCommand)
-
- { These fields are for the command objects that we use. The first one we need
- for sure is the selection object to handle the mouse selection in the content
- region of the view. }
- fOwnerView: TFracAppView;
-
-
- PROCEDURE TAreaSelector.IAreaSelector(ownerView: TFracAppView; startPt: Point);
- { Initialize the selection object itself. This basically sets up with IObject,
- then sets the fSelectionRect to be a minimal rectangle. }
-
- FUNCTION TAreaSelector.TrackMouse(aTrackPhase: TrackPhase;
- VAR anchorPoint, previousPoint, nextPoint: VPoint;
- mouseDidMove: BOOLEAN): TCommand; OVERRIDE;
- { Track the mouse while the button is down in the view. }
-
- PROCEDURE TAreaSelector.TrackFeedback(anchorPoint, nextPoint: VPoint;
- turnItOn, mouseDidMove: BOOLEAN); OVERRIDE;
- { Feedback that matches better, using the selection pattern. }
-
- PROCEDURE TAreaSelector.TrackConstrain(anchorPoint, previousPoint: VPoint;
- VAR nextPoint: VPoint); OVERRIDE;
- { Constrain the mouse movement to be a rect which matches the screen. }
-
- END; { TAreaSelector }
-
-
- IMPLEMENTATION
-
- {$I UFracApp.inc1.p}
-
- END.
-